home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Internet Info 1994 March
/
Internet Info CD-ROM (Walnut Creek) (March 1994).iso
/
networking
/
ip
/
slip
/
sl.shar
/
sl
/
src
/
local
/
dstaddr.c
next >
Wrap
C/C++ Source or Header
|
1988-04-12
|
1KB
|
72 lines
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <net/if.h>
#include <netinet/in.h>
#include <stdio.h>
#include <ctype.h>
#include <netdb.h>
struct ifreq ifr;
int s;
main(argc, argv)
int argc;
char *argv[];
{
char *strncpy();
if (argc < 3) {
(void) fprintf(stderr, "usage: %s interface dest_addr\n", argv[0]);
exit(1);
}
(void) strncpy(ifr.ifr_name, argv[1], strlen(argv[1]) + 1);
s = socket(AF_INET, SOCK_DGRAM, 0);
if (s < 0) {
perror("socket");
exit(1);
}
if (ioctl(s, SIOCGIFFLAGS, (caddr_t)&ifr) < 0) {
perror("ioctl (SIOCGIFFLAGS)");
exit(1);
}
in_getaddr(argv[2], &ifr.ifr_addr);
if (ioctl(s, SIOCSIFDSTADDR, (caddr_t)&ifr) < 0)
perror("ioctl (SIOCSIFDSTADDR)");
}
struct in_addr inet_makeaddr();
in_getaddr(s, saddr)
char *s;
struct sockaddr *saddr;
{
register struct sockaddr_in *sin = (struct sockaddr_in *)saddr;
struct hostent *hp;
struct netent *np;
int val;
sin->sin_family = AF_INET;
val = inet_addr(s);
if (val != -1) {
sin->sin_addr.s_addr = val;
return;
}
hp = gethostbyname(s);
if (hp) {
sin->sin_family = hp->h_addrtype;
bcopy(hp->h_addr, (char *)&sin->sin_addr, hp->h_length);
return;
}
np = getnetbyname(s);
if (np) {
sin->sin_family = np->n_addrtype;
sin->sin_addr = inet_makeaddr(np->n_net, INADDR_ANY);
return;
}
(void) fprintf(stderr, "%s: bad value\n", s);
exit(1);
}